home *** CD-ROM | disk | FTP | other *** search
/ PC User 2003 January / Disc 3 / Amethyst.iso / live / usr / lib / rpm-3.0.6 / perl.req < prev    next >
Encoding:
Text File  |  2001-04-06  |  5.4 KB  |  200 lines

  1. #!/usr/bin/perl
  2.  
  3. # RPM (and it's source code) is covered under two separate licenses. 
  4.  
  5. # The entire code base may be distributed under the terms of the GNU
  6. # General Public License (GPL), which appears immediately below.
  7. # Alternatively, all of the source code in the lib subdirectory of the
  8. # RPM source code distribution as well as any code derived from that
  9. # code may instead be distributed under the GNU Library General Public
  10. # License (LGPL), at the choice of the distributor. The complete text
  11. # of the LGPL appears at the bottom of this file.
  12.  
  13. # This alternatively is allowed to enable applications to be linked
  14. # against the RPM library (commonly called librpm) without forcing
  15. # such applications to be distributed under the GPL.
  16.  
  17. # Any questions regarding the licensing of RPM should be addressed to
  18. # Erik Troan <ewt@redhat.com>.
  19.  
  20. # a simple makedepends like script for perl.
  21.  
  22. # To save development time I do not parse the perl grammmar but
  23. # instead just lex it looking for what I want.  I take special care to
  24. # ignore comments and pod's.
  25.  
  26. # It would be much better if perl could tell us the dependencies of a
  27. # given script.
  28.  
  29. # The filenames to scan are either passed on the command line or if
  30. # that is empty they are passed via stdin.
  31.  
  32. # If there are strings in the file which match the pattern
  33. #     m/^\s*\$RPM_Requires\s*=\s*["'](.*)['"]/i
  34. # then these are treated as additional names which are required by the
  35. # file and are printed as well.
  36.  
  37. # I plan to rewrite this in C so that perl is not required by RPM at
  38. # build time.
  39.  
  40. # by Ken Estes Mail.com kestes@staff.mail.com
  41.  
  42. if ("@ARGV") {
  43.   foreach (@ARGV) {
  44.     process_file($_);
  45.   }
  46. } else {
  47.   
  48.   # notice we are passed a list of filenames NOT as common in unix the
  49.   # contents of the file.
  50.   
  51.   foreach (<>) {
  52.     process_file($_);
  53.   }
  54. }
  55.  
  56.  
  57. foreach $module (sort keys %require) {
  58.   if (length($require{$module}) == 0) {
  59.     print "perl($module)\n";
  60.   } else {
  61.  
  62.     # I am not using rpm3.0 so I do not want spaces arround my
  63.     # operators. Also I will need to change the processing of the
  64.     # $RPM_* vairable when I upgrage.
  65.  
  66.     print "perl($module) >= $require{$module}\n";
  67.   }
  68. }
  69.  
  70. exit 0;
  71.  
  72.  
  73.  
  74. sub process_file {
  75.   
  76.   my ($file) = @_;
  77.   chomp $file;
  78.   
  79.   open(FILE, "<$file")||
  80.     die("$0: Could not open file: '$file' : $!\n");
  81.   
  82.   while (<FILE>) {
  83.     
  84.     # skip the documentation
  85.  
  86.     # we should not need to have item in this if statement (it
  87.     # properly belongs in the over/back section) but people do not
  88.     # read the perldoc.
  89.  
  90.     if ( (m/^=(head1|head2|pod|item)/) .. (m/^=(cut)/) ) {
  91.       next;
  92.     }
  93.  
  94.     if ( (m/^=(over)/) .. (m/^=(back)/) ) {
  95.       next;
  96.     }
  97.     
  98.     # skip the data section
  99.     if (m/^__(DATA|END)__$/) {
  100.       last;
  101.     }
  102.  
  103.     # Each keyword can appear multiple times.  Don't
  104.     #  bother with datastructures to store these strings,
  105.     #  if we need to print it print it now.
  106.     
  107.     if ( m/^\s*\$RPM_Requires\s*=\s*["'](.*)['"]/i) {
  108.       foreach $_ (spit(/\s+/, $1)) {
  109.     print "$_\n";
  110.       }
  111.     }
  112.  
  113.     if ( 
  114.  
  115. # ouch could be in a eval, perhaps we do not want these since we catch
  116. # an exception they must not be required
  117.  
  118. #   eval { require Term::ReadLine } or die $@;
  119. #   eval "require Term::Rendezvous;" or die $@;
  120. #   eval { require Carp } if defined $^S; # If error/warning during compilation,
  121.  
  122.  
  123.     (m/^\s*         # we hope the inclusion starts the line
  124.      (do|require|use)\s+(?!\{)     # do not want 'do {' loops
  125.      # quotes around name are always legal
  126.      [\'\"]?([^\;\ \'\"\t]*)[\'\"]?[\t\;\ ]
  127.      # the syntax for 'use' allows version requirements
  128.      \s*([.0-9]*)
  129.      /x)
  130.        ) {
  131.       my ($module, $version) = ($2,$3);
  132.  
  133.       # if there is some interpolation of variables just skip this
  134.       # dependency, we do not want
  135.       #        do "$ENV{LOGDIR}/$rcfile";
  136.    
  137.       ($module =~ m/\$/) && next;
  138.  
  139.       # if the module ends in a comma we probaly caught some
  140.       # documentation of the form 'check stuff,\n do stuff, clean
  141.       # stuff.' there are several of these in the perl distribution
  142.  
  143.       ($module  =~ m/[,>]$/) && next;
  144.  
  145.       # if the module name starts in a dot it is not a module name.
  146.       # Is this necessary?  Please give me an example if you turn this
  147.       # back on.
  148.  
  149.       #      ($module =~ m/^\./) && next;
  150.  
  151.       # if the module ends with .pm strip it to leave only basename.
  152.  
  153.       $module =~ s/\.pm$//;
  154.  
  155.       # some perl programmers write 'require URI/URL;' when 
  156.       # they mean 'require URI::URL;'
  157.  
  158.       $module =~ s/\//::/;
  159.  
  160.       # trim off trailing parenthesis if any.  Sometimes people pass
  161.       # the module an empty list.
  162.  
  163.       $module =~ s/\(\s*\)$//;
  164.  
  165.       if ( $module =~ m/^[0-9._]+$/ ) {
  166.       # if module is a number then both require and use interpret that
  167.       # to mean that a particular version of perl is specified
  168.  
  169.     print "perl > $module\n";
  170.     next;
  171.       };
  172.  
  173.       # ph files do not use the package name inside the file.
  174.       # perlmodlib  documentation says:
  175.       
  176.       #       the .ph files made by h2ph will probably end up as
  177.       #       extension modules made by h2xs.
  178.       
  179.       # so do not expend much effort on these.
  180.  
  181.  
  182.       # there is no easy way to find out if a file named systeminfo.ph
  183.       # will be included with the name sys/systeminfo.ph so only use the
  184.       # basename of *.ph files
  185.  
  186.       ($module  =~ m/\.ph$/) && ($module =~ s!.*/!!g );
  187.  
  188.  
  189.       $require{$module}=$version;
  190.       $line{$module}=$_;
  191.     }
  192.     
  193.   }
  194.  
  195.   close(FILE)||
  196.     die("$0: Could not close file: '$file' : $!\n");
  197.   
  198.   return ; 
  199. }
  200.